package org.activemonitoring.config;

import org.activemonitoring.datastore.dao.DataStoreDao;
import org.activemonitoring.datastore.jms.client.DataStoreJmsClient;
import org.activemonitoring.datastore.rest.client.DataStoreRestClient;
import org.activemonitoring.harvesters.Harvester;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import static org.junit.Assert.assertEquals;

public class LoadConfigurationCase {

    @Test
    public void testConfigurationLoad() {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(new String[] {
                "applicationContext-harvesters.xml", "applicationContext-datastore.xml",
                "applicationContext-test-directjava.xml" });
        applicationContext.start();
        Harvester harvester = applicationContext.getBean("harvester", Harvester.class);
        assertEquals(DataStoreDao.class, harvester.getDataStore().getClass());
        applicationContext.stop();
    }

    @Test
    public void testConfigurationLoadWithSpringConfig() {
        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(
                new String[] { "applicationContext-test-spring-config.xml" });
        applicationContext.start();

        Harvester harvester = applicationContext.getBean("harvesterWithJms", Harvester.class);
        assertEquals(DataStoreJmsClient.class, harvester.getDataStore().getClass());

        harvester = applicationContext.getBean("harvesterWithDao", Harvester.class);
        assertEquals(DataStoreDao.class, harvester.getDataStore().getClass());

        harvester = applicationContext.getBean("harvesterWithRest", Harvester.class);
        assertEquals(DataStoreRestClient.class, harvester.getDataStore().getClass());

        applicationContext.stop();
    }
}
